/*
Copyright [2020] [https://www.xiaonuo.vip]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：

1.请不要删除和修改根目录下的LICENSE文件。
2.请不要删除和修改Snowy源码头部的版权声明。
3.请保留源码和相关描述文件的项目出处，作者声明等。
4.分发源码时候，请注明软件出处 https://gitee.com/xiaonuobase/snowy-layui
5.在修改包名，模块名称，项目代码等时，请注明软件出处 https://gitee.com/xiaonuobase/snowy-layui
6.若您的项目无法满足以上几点，可申请商业授权，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.modular.controller;

import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.annotion.Permission;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.page.PageResult;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.entity.Report;
import vip.xiaonuo.modular.mapper.ReportMapper;
import vip.xiaonuo.modular.param.ReportParam;
import vip.xiaonuo.modular.service.ReportService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

/**
 * 应急信息快报控制器
 *
 * @author 梨落
 * @date 2022-02-17 13:23:11
 */
@Controller
public class ReportController {

    private String PATH_PREFIX = "report/";

    @Resource
    private ReportService reportService;

    @Resource
    private ReportMapper reportMapper;

    /**
     * 应急信息快报页面
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */
    @Permission
    @GetMapping("/report/index")
    public String index() {
        return PATH_PREFIX + "index.html";
    }

    /**
     * 应急信息快报表单页面
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */

    @GetMapping("/report/form")
    public String form() {
        return PATH_PREFIX + "form.html";
    }

    /**
     * 应急信息快报表单页面
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */
    @GetMapping("/report/diaobo")
    public String diaobo() {
        return PATH_PREFIX + "diaobo.html";
    }

    @GetMapping("/report/diaobowz")
    public String diaobowz() {
        return PATH_PREFIX + "diaobowz.html";
    }

    @GetMapping("/report/place")
    public String place() {
        return PATH_PREFIX + "place.html";
    }

    /**
     * 查询应急信息快报
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */
    @Permission
    @ResponseBody
    @GetMapping("/report/page")
    @BusinessLog(title = "应急信息快报_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public PageResult<Report> page(ReportParam reportParam) {
        return reportService.page(reportParam);
    }

    /**
     * 添加应急信息快报
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */
    @Permission
    @ResponseBody
    @PostMapping("/report/add")
    @BusinessLog(title = "应急信息快报_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(ReportParam.add.class) ReportParam reportParam) {
        reportService.add(reportParam);
        return new SuccessResponseData();
    }

    /**
     * 删除应急信息快报
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */
    @Permission
    @ResponseBody
    @PostMapping("/report/delete")
    @BusinessLog(title = "应急信息快报_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(ReportParam.delete.class) List<ReportParam> reportParamList) {
        reportService.delete(reportParamList);
        return new SuccessResponseData();
    }

    @Permission
    @ResponseBody
    @PostMapping("/report/ry")
    @BusinessLog(title = "应急信息人员调拨")
    public ResponseData ry(@RequestBody List<ReportParam> reportParam) {
        reportParam.get(0).setState(2);
        reportService.edit(reportParam.get(0));
        return new SuccessResponseData();
    }


    @Permission
    @ResponseBody
    @PostMapping("/report/wz")
    @BusinessLog(title = "应急信息物资调拨")
    public ResponseData wz(@RequestBody List<ReportParam> reportParam) {
        reportParam.get(0).setState(3);
        reportService.edit(reportParam.get(0));
        return new SuccessResponseData();
    }


    @Permission
    @ResponseBody
    @PostMapping("/report/sp")
    @BusinessLog(title = "应急审批")
    public ResponseData sp(@RequestBody List<ReportParam> reportParam) {
        reportParam.get(0).setState(4);
        reportService.edit(reportParam.get(0));
        return new SuccessResponseData();
    }

    /**
     * 编辑应急信息快报
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */
    @Permission
    @ResponseBody
    @PostMapping("/report/edit")
    @BusinessLog(title = "应急信息快报_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(ReportParam.edit.class) ReportParam reportParam) {
        if (reportParam.getWuzi()!=null){
            reportParam.setState(1);
        }
        reportService.edit(reportParam);
        return new SuccessResponseData();
    }

    @ResponseBody
    @PostMapping("/report/db")
    @BusinessLog(title = "应急信息快报_db")
    public ResponseData db(@RequestBody @Validated(ReportParam.edit.class) ReportParam reportParam) {
        if (reportParam.getWuzi()!=null&&reportParam.getWuzi()!=""){
            reportParam.setState(1);
        }
        reportService.edit(reportParam);
        return new SuccessResponseData();
    }
/*    *//**
     * 编辑应急信息调拨
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     *//*
    @Permission
    @ResponseBody
    @PostMapping("/report/diaobo")
    @BusinessLog(title = "应急信息快报_调拨", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData diaobo(@RequestBody @Validated(ReportParam.edit.class) ReportParam reportParam) {
        reportService.edit(reportParam);
        return new SuccessResponseData();
    }*/

    /**
     * 查看应急信息快报
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */
    @Permission
    @ResponseBody
    @GetMapping("/report/detail")
    @BusinessLog(title = "应急信息快报_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(ReportParam.detail.class) ReportParam reportParam) {
        return new SuccessResponseData(reportService.detail(reportParam));
    }

    /**
     * 应急信息快报列表
     *
     * @author 梨落
     * @date 2022-02-17 13:23:11
     */
    @Permission
    @ResponseBody
    @GetMapping("/report/list")
    @BusinessLog(title = "应急信息快报_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(ReportParam reportParam) {
        return new SuccessResponseData(reportService.list(reportParam));
    }

}
